<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>1班抽奖</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    h2 {
      text-align: center;
    }

    .box {
      width: 600px;
      margin: 50px auto;
      display: flex;
      font-size: 25px;
      line-height: 40px;
    }

    .qs {

      width: 450px;
      height: 40px;
      color: red;

    }

    .btns {
      text-align: center;
    }

    .btns button {
      width: 120px;
      height: 35px;
      margin: 0 50px;
    }
  </style>
</head>

<body>
  <h2>随机点名</h2>
  <div class="box">
    <span>大冤种：</span>
    <div class="qs">请点击开始进行抽奖</div>
  </div>
  <div class="btns">
    <button class="start">开始</button>
    <button class="end">结束</button>
  </div>

  <script>
    // 数据数组
    const arr = ["张三", "罗衡", "赖炜强", "刘鹏程", "叶子青", "张文琦", "张云飞", "姚涛", "黄兴婷", "甘建华", "胡佳兴", "徐婷婷", "刘堉源", "童健", "马如意", "邓贝贝", "梅越", "吴云有", "陈广豪", "朱越辉", "黄慧瑾", "林鑫杨", "徐诗婧", "左文豪", "万成欣", "沈漫", "徐慧婷", "付文彤", "胡楠", "宋语", "康子豪", "祝航欣", "徐一敏", "兰盺硕", "彭智辉", "肖长明", "周义轩", "陈友浩", "曾妍", "刘志鹏", "徐建斌", "王煜政", "曾嘉坤", "胡云飞", "吴联福", "饶晶晶", "吴佳琪", "占昊", "王亚文", "颜昌新", "吴子杰", "袁源强", "黄旭", "丁丽", "柯子安", "黄宁", "曾敏"];
    // 定时器的全局变量
    let timerId = 0
    // 随机号要全局变量
    let random = 0
    // 业务1.开始按钮模块
    const qs = document.querySelector('.qs')
    // 1.1 获取开始按钮对象
    const start = document.querySelector('.start')
    // 1.2 添加点击事件
    start.addEventListener('click', function () {
      timerId = setInterval(function () {
        // 随机数
        random = parseInt(Math.random() * arr.length)
        // console.log(arr[random])
        qs.innerHTML = arr[random]
      }, 100)
    })

    // 2. 关闭按钮模块
    const end = document.querySelector('.end')
    end.addEventListener('click', function () {
      clearInterval(timerId)
    })
  </script>
</body>

</html>